﻿namespace Borg
{
    public class ExtensionContext
    {
        private readonly ExtensionPersistor _persistor;
        private readonly ExtensionLogger _logger;

        public Extension Extension { get; private set; }

        private Runtime Runtime
        {
            get { return Extension.Runtime; }
        }

        public ExtensionPersistor Persistor
        {
            get { return _persistor; }
        }

        public ExtensionLogger Logger
        {
            get { return _logger; }
        }

        public SettingDictionary Settings
        {
            get { return Runtime.SettingStore.GetSettings(Extension.ExtensionType); }
            set { Runtime.SettingStore.SetSettings(Extension.ExtensionType, value); }
        }

        internal ExtensionContext(Extension extension)
        {
            Extension = extension;
            _persistor = new ExtensionPersistor(Runtime.Persistor, Extension);
            _logger = new ExtensionLogger(Runtime.Logger, Extension);
        }
    }
}
